Hi, |
Re: Count Within Month
Well the idea is to first get the start and the end of the month as a date. I like to use a trick for that (string / int conversion):
string pad2(int nr) { return (nr < 10) ? ("0" nr "") : (nr "") }
Date startOfMonth (Date d) {
if (null d) return d
int m = intOf stringOf (d, "MM")
int y = intOf stringOf (d, "yy")
Date result = date("01/" (pad2 m) "/" (pad2 y), "dd/MM/yy")
return result
}
Date endOfMonth (Date d) {
if (null d) return d
int m = intOf stringOf (d, "MM")
int y = intOf stringOf (d, "yy")
// increase the month
y = (m == 12) ? (y+1) : y
m = (m == 12) ? 1 : (m+1)
Date result = date("01/" (pad2 m) "/" (pad2 y), "dd/MM/yy")
return dateOnly dateOf ((intOf result) - 60*60*24)
}
Date d
d = date("15/02/2012", "dd/MM/yyyy")
print "The start of February is: " (startOfMonth d) "\n"
print "The end of February is: " (endOfMonth d) "\n\n"
d = date("15/12/2012", "dd/MM/yyyy")
print "The start of December is: " (startOfMonth d) "\n"
print "The end of December is: " (endOfMonth d) "\n\n"
d = date("15/01/2012", "dd/MM/yyyy")
print "The start of January is: " (startOfMonth d) "\n"
print "The end of January is: " (endOfMonth d) "\n\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Count Within Month I went about it differently:
const int cl_SecsInDay = 60*60*24
//*******************
int fDateToDays(Date dateIn)
{ // Convert the date to the number of days since DOORS date origin started
return(intOf(dateIn)/cl_SecsInDay)
} // end fDateToDays()
//******************
Date fDaysToDate(int Days)
{ // Convert the integer representing # Days to a date,
// Days must be positive or zero
return(dateOf(Days*cl_SecsInDay))
} // end fDaysToDate()
Date fDaysAgo(int DaysAgo)
{ // Get the date it was that many DaysAgo
int DaysNow = fDateToDays(dateOnly(today()))
return(dateOnly(fDaysToDate(DaysNow - DaysAgo)))
}
void Test(int DaysAgo)
{
print DaysAgo "\t" fDaysAgo(DaysAgo) "\n"
}
Test(1)
Test(30)
|
Re: Count Within Month llandale - Mon Jun 18 16:37:00 EDT 2012 I went about it differently:
const int cl_SecsInDay = 60*60*24
//*******************
int fDateToDays(Date dateIn)
{ // Convert the date to the number of days since DOORS date origin started
return(intOf(dateIn)/cl_SecsInDay)
} // end fDateToDays()
//******************
Date fDaysToDate(int Days)
{ // Convert the integer representing # Days to a date,
// Days must be positive or zero
return(dateOf(Days*cl_SecsInDay))
} // end fDaysToDate()
Date fDaysAgo(int DaysAgo)
{ // Get the date it was that many DaysAgo
int DaysNow = fDateToDays(dateOnly(today()))
return(dateOnly(fDaysToDate(DaysNow - DaysAgo)))
}
void Test(int DaysAgo)
{
print DaysAgo "\t" fDaysAgo(DaysAgo) "\n"
}
Test(1)
Test(30)
This maybe an even easier solution:-
string sMonth = "/04/2012"
Module m = current
Object o = current
Regexp rDate = regexp sMonth
int cnt = 0
History h
for o in entire m do {
for h in o do {
if (rDate stringOf (h.date))
{
cnt++
break
}
}
}
print cnt " objects modified in month " sMonth
|
Re: Count Within Month Martin_Hunter - Tue Jun 19 06:02:39 EDT 2012
This maybe an even easier solution:-
string sMonth = "/04/2012"
Module m = current
Object o = current
Regexp rDate = regexp sMonth
int cnt = 0
History h
for o in entire m do {
for h in o do {
if (rDate stringOf (h.date))
{
cnt++
break
}
}
}
print cnt " objects modified in month " sMonth
Thanks! |